<!doctype html>
<html>
<head>
    <link rel="shortcut icon" href="favicon.ico" />
    <meta content="ie=11.0000" http-equiv="x-ua-compatible">
    <meta charset="utf-8"> <title>sugou 商城</title>
    <meta http-equiv="keywords" content="sugou 商城">
    <meta name="description" content="sugoushop sugou 商城">
    <script src="__JS__/jquery-1.10.2.min.js"></script>
    <script src="__JS__/global.js"></script>
    <script src="__JS__/pc_common.js"></script>

    <script type="text/javascript">

            function price(o){
                var tr = o.closest('tr');
                var xiaoji = tr.find('#xiaoji');
                var market_price = $('#market_price').html();
                xiaoji.html(parseInt(o.val()) * parseInt(market_price));
                var sum = 0;
                sum+=parseInt(xiaoji.html());
                $("#heji").html(sum+'元');
            }


            //减
            function minusCart(_this, id){
                var num_input = $(_this).next('input[name="num"]');
                var num = parseInt(num_input.val());
                num--;
                if(num <= 0){
                    return false;
                } else {
                    num_input.val(num);
                    price(num_input);
                    cartNum(num_input, id, num);
                }
            }
            //加
            function plusCart(_this,id){
                //获取购买数量
                var num_input = $(_this).prev('input[name="num"]');
                var num = parseInt(num_input.val());
                num = parseInt(num) + 1;
                num_input.val(num);
                price(num_input);
                cartNum(num_input, id, num);

            }

            function cartNum(_this, id, num){
                $.ajax({
                    type: 'POST',
                    url: "{:url('index/index/ajaxReturn')}",
                    data: {id: id, num: num},
                    dataType: 'json',
                    success: function (res) {
                        if (res.status == 1) {
                            _this.val(num);
                        }else{
                            alert(res.info);
                        }
                    }
                });
            }


            function changePrice(id){
                var num_input = $('#num');
                var num = parseInt(num_input.val());
                var market_price = $('#market_price').html();
                $('#xiaoji').html(parseInt(num) * parseInt(market_price));
                var sum = 0;
                sum+=parseInt($('#xiaoji').html());
                $("#heji").html(sum+'元');

                cartNum(num_input, id, num);
            }


    </script>


</head>
<body>
<link href="__CSS__/style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="__CSS__/goods_cart.css"/>
<div class="site-topbar">
    <div class="layout">
        <div class="t1-l">
            <ul class="t1-l-ul">
                <li class="t1font"><a href="{:url('index/index/index')}">Sugoushop</a></li>
                <li class="t1img">&nbsp;</li>
            </ul>
        </div>
        <div class="t1-r">

            {if condition="session('islogin')"}
            <ul class="t1-r-ul">
                <li class="t1font"> <a href="#" class="logon userinfo">{$Think.session.username}</a></li>
                <li class="t1img"><a href="#">安全退出</a></li>
                <li class="t1img">&nbsp;</li>
                <li class="t1img">&nbsp;</li>
                <li class="t1font"><a href="#">我的订单</a></li>
            </ul>
            {else /}
            <ul class="t1-r-ul">
                <li class="t1font"><a href="{:url('index/user/login')}">登录</a></li>
                <li class="t1img">&nbsp;</li>
            </ul>
            {/if}
        </div>
    </div>
</div>
<div class="order-header">
    <div class="layout after">
        <div class="fl">
            <div class="logo wi345">
                <a href="index.php"><img alt="" src="img/logofinal3.png"></a>
            </div>
        </div>
        <div class="fr">
            <div class="pa-to-36 progress-area">
                <div class="progress-area-wd">我的购物车</div>
                <div class="progress-area-tx" style="display: none;">填写核对订单信息</div>
                <div class="progress-area-cg" style="display: none;">成功提交订单</div>
            </div>
        </div>
    </div>
</div>
<div class="layout after-ta">
    <div class="sc-list">
        <form name="cart_form" id="cart_form" action="">
            <div id="ajax_return">

                <div class="sc-pro-list">
                    <table width="100%" border="0" cellspacing="0" cellpadding="1">
                        <tbody><tr class="ba-co-danhui">
                            <th align="center" class="pa-le-9" valign="middle">&nbsp;&nbsp;</th>
                            <th align="center" valign="middle" colspan="2">商品</th>
                            <th align="center" valign="middle">单价（元）</th>
                            <th align="center" valign="middle">数量</th>
                            <th align="center" valign="middle">小计（元）</th>
                            <th align="center" valign="middle">操作</th>
                        </tr>
                        {foreach name='cart' item='vo'}

                        <tr>
                            <td align="center" class="pa-le-9" valign="middle" style="border-right-color: currentColor; border-right-width: 0px; border-right-style: none;">
                                <input name="cart_select[4017]" onclick="" type="checkbox" checked="checked" value="1">
                            </td>
                            <td width="80" align="center" class="pa-to-20 pa-bo-20 bo-ri-0" valign="top" style="border-right-color: currentColor; border-left-color: currentColor; border-right-width: 0px; border-left-width: 0px; border-right-style: none; border-left-style: none;">
                                <a class="gwc-wp-list di-bl wi63 hi63" href="#">
                                    <img class="wi63 hi63" src="__ROOT__/images/2/1.jpg">
                                </a>
                            </td>
                            <td align="left" class="pa-to-20 wi516" valign="top" style="border-left-color: currentColor;border-left-width: 0px;border-left-style: none;padding-top: 45px;width: 700px;">
                                <a style="vertical-align: middle;" href="{:url('index/index/details',['goods_id'=>$vo.id])}">{$vo.goods_name}</a>
                            </td>
                            <td align="center" valign="middle" id="market_price">{$vo.market_price}</td>
                            <td align="center" valign="middle">
                                <div class="sc-stock-area">
                                    <div class="stock-area">
                                        <a title="减" onclick="minusCart(this,{$vo.id})">-</a>
                                        <input name="num" class="wi43 fl" id="num" type="text"  value="{$vo.goods_num}" onchange="changePrice({$vo.id})">
                                        <a title="加" onclick="plusCart(this, {$vo.id});">+</a>
                                    </div>
                                </div>
                            </td>
                            <td align="center" valign="middle" id="xiaoji">{$vo.market_price*$vo.goods_num}</td>
                            <td align="center" valign="middle">
                                <a class="gwc-gb" onclick="return confirm('删除后无法恢复,确定要删除吗')"
                                   href="cart_del.php?id={$vo.id}"></a></td>
                        </tr>
                        {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="sc-total-list ma-to-20 sc-pro-list">
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tbody>
                        <tr>
                            <td width="270" align="right" id="bo-to-dedede">合计：</td>
                            <td width="70" align="middle" id="bo-to-dedede"><em id="heji">{$vo.market_price*$vo.goods_num}元</em></td>
                        </tr>
                        </tbody></table>
                </div>
            </div>
        </form>
        <div class="sc-acti-list ma-to-20 ma-bo-135">
            <a class="gwc-jxgw" href="{:url('index/index/index')}">继续购物</a>
            <a class="gwc-qjs" href="goods_jiesuan.php?cartid={$vo.id}">去结算</a>
        </div>
    </div>
</div>
<!--------footer-开始-------------->
{include file='/footer'}
<!--------footer-结束-------------->

</body>
</html>